<?php

class Member_bankAction extends CommonAction
{

    public function _initialize()
    {
        parent::_initialize();
    }
	
	  public function integral_detail()
    {
		
		 $afflist = $payment = M('Affiliatesetting')->where(array('site_id' => 143, 'status' => 1))->find();
		 
		$afflist = unserialize($afflist['value']);
		$aff=$afflist['draw'];
        $bank_db=M('Member_bank');
     
        $myid = D('User')->where(' id = ' . session(C('USER_AUTH_KEY')))->getField('member_id');
		$member = M('Member')->where('id = ' . $myid)->find();
        if (IS_POST) {
            
           
           $demomey = (float)$this->_post('demomey');
          // $this->error($member['repwd']);
            if (MD5($_POST['password']) != $member['repwd']) {
                $this->error('密码错误');
                exit();
            }
		$bank=$bank_db->where(array('id'=>$_POST['account']))->find();
        if($bank['accountname']!=$_POST['accountname']){
         $this->error('你输入的账号与开户名不匹配！');   
        }
		
		$afflist = $payment = M('Affiliatesetting')->where(array('site_id' => __SITEID__, 'status' => 1))->find();
		
$afflist = M('Affiliatesetting')->where(array('site_id' => __SITEID__, 'status' => 1))->find();
			 
			$afflist = unserialize($afflist['value']);
		
 			if ($this->_post('txstate') == 1 && $demomey > 2000) {
                $this->error("提现不能超过2000元!");
                exit;
            }
            if ($this->_post('txstate') == 1 && $demomey < 100) {
                $this->error("提现不能小于100元!");
                exit;
            }
			$_POST['fee']=$afflist['draw'][$member['level']];
			
			
			  $data = array(
                'product_id' => 0,
                'status' => 0,
                'site_id' => __SITEID__,
                'order_id' => 0,
                'remark' => $member['nickname'] . "用户，申请积分提现。提现金额:" . $demomey . "  手续费:" . $_POST['fee'] ,
                'dateline' => time(),
                'changenum' => $demomey - $_POST['fee'],
                'mem_brankid' => $_POST['account'],
                'pdstate' => 2,
                'hbstatus' => '2',
                'goodsMoney' => $demomey,
				'member_id' => $member['id'],
                C('TOKEN_NAME') => $_POST[C('TOKEN_NAME')]
            );
			
			$Member_account_log = D('Member_account_log');
           


            if (!$Member_account_log->create($data)) {
                $this->error($Member_account_log->getError());
                exit;
            }
		
            $mes = $Member_account_log->data($data)->add();
			   if ($mes) {
				
                $memberDB = M('member');
                $member = $memberDB->where(array('id' => $member['id']))->find();
                $money = $member['money'] - $demomey;
                $memberDB->where(array('id' => $member['id']))->save(array('offline' => $money));
			
                $this->success('提现成功，正提交审核！', U('Index/index'));
                exit;
            } else {
                $this->error('提现失败');
                exit;
            }
	  }
	  $this->assign('aff',$aff[$member['level']]);
	
      $txstate = 1;
	  $this->assign('txstate', $txstate);
      $member=M('Member')->where('id = '.$myid)->find();
      $bank_list = $bank_db->where(' member_id = ' . $myid)->select();  
      $this->assign('member',$member);
      $this->assign('bank_list',$bank_list);
      $this->display();
  
	}

    public function detail()
    {
        $bank_db=M('Member_bank');
     
	 
	  $afflist = $payment = M('Affiliatesetting')->where(array('site_id' => 143, 'status' => 1))->find();
		 
		$afflist = unserialize($afflist['value']);
		$aff=$afflist['draw'];
        $myid = D('User')->where(' id = ' . session(C('USER_AUTH_KEY')))->getField('member_id');
		 $member = M('Member')->where('id = ' . $myid)->find();
        if (IS_POST) {
            
          
           $demomey = (float)$this->_post('demomey');
          // $this->error($member['repwd']);
            if (MD5($_POST['password']) != $member['repwd']) {
                $this->error('密码错误');
                exit();
            }
		$bank=$bank_db->where(array('id'=>$_POST['account']))->find();
        if($bank['accountname']!=$_POST['accountname']){
         $this->error('你输入的账号与开户名不匹配！');   
        }
		
		$afflist = $payment = M('Affiliatesetting')->where(array('site_id' => __SITEID__, 'status' => 1))->find();
		
$afflist = M('Affiliatesetting')->where(array('site_id' => __SITEID__, 'status' => 1))->find();
			 
			$afflist = unserialize($afflist['value']);
		
 			if ($this->_post('txstate') == 1 && $demomey > 2000) {
                $this->error("提现不能超过2000元!");
                exit;
            }
            if ($this->_post('txstate') == 1 && $demomey < 100) {
                $this->error("提现不能小于100元!");
                exit;
            }
			$_POST['fee']=$afflist['draw'][$member['level']];
			
			
			  $data = array(
                'product_id' => 0,
                'status' => 0,
                'site_id' => __SITEID__,
                'order_id' => 0,
                'remark' => $member['nickname'] . "用户，申请提现。提现金额:" . $demomey . "  手续费:" . $_POST['fee'] . "%",
                'dateline' => time(),
                'changenum' => $demomey - $_POST['fee'],
                'mem_brankid' => $_POST['account'],
                'pdstate' => 2,
                'hbstatus' => $this->_post('txstate'),
                'goodsMoney' => $demomey,
				'member_id' => $member['id'],
                C('TOKEN_NAME') => $_POST[C('TOKEN_NAME')]
            );
			
			$Member_account_log = D('Member_account_log');
           


            if (!$Member_account_log->create($data)) {
                $this->error($Member_account_log->getError());
                exit;
            }
		
            $mes = $Member_account_log->data($data)->add();
			   if ($mes) {
				
                $memberDB = M('member');
                $member = $memberDB->where(array('id' => $member['id']))->find();
                $money = $member['money'] - $demomey;
                $memberDB->where(array('id' => $member['id']))->save(array('money' => $money));
			
                $this->success('提现成功，正提交审核！', U('Index/index'));
                exit;
            } else {
                $this->error('提现失败');
                exit;
            }
	
		 
        }
        
        $this->assign('aff',$aff[$member['level']]);
      $txstate = 1;
	  $this->assign('txstate', $txstate);
      $member=M('Member')->where('id = '.$myid)->find();
      $bank_list = $bank_db->where(' member_id = ' . $myid)->select();  
      $this->assign('member',$member);
      $this->assign('bank_list',$bank_list);
      $this->display();
    }

    public function index()
    {
        $pagesize = 5;
        if ($this->_get('pagesize')) {
            $pagesize = $this->_get('pagesize');
        }
        // 实例化分页类
        import('ORG.Util.Page');
        // $listmap = 's.site_id = 143 ';
        $authId = session('authId');
        $myid = D('User')->where(' id = ' . session(C('USER_AUTH_KEY')))->getField('member_id');
        if(D('Member')->where('id = '.$myid)->getfield('level')==1){
            $this->listmap = 'member_id = ' . $myid;
            if ($this->_get('keywords')) {
                $this->keywords = $this->_get('keywords');
            }
            $this->initView();

            parent::_list($this->view, '', '');
        }
        $this->display();
    }
	
	

    public function bank_list()
    {
        $myid = D('User')->where(' id = ' . session(C('USER_AUTH_KEY')))->getField('member_id');
        
        if ($myid > 0) {
            $this->listmap = 'member_id = ' . $myid;
            if ($this->_get('keywords')) {
                
                $this->keywords = $this->_get('keywords');
            }
            if (isset($_GET['level'])) {}
            
            $this->initView();
            
            parent::_list($this->view, '', '');
        }
        $this->display();
    }

    public function bank_add()
    {
        if (IS_POST) {
            parent::insert($_POST);
        }
        
        $this->display();
        exit();
    }
    public function edit(){
        if($_GET['id']){
            $this->list=$this->dao->where('id = '.$_GET['id'])->find();
        }
        $this->display();
    }
}

?>